package com.ramms.eater.activity;

import com.ramms.eater.R;
import com.ramms.eater.manager.OnClickListenerManager;
import com.ramms.eater.parser.SectionParser;
import com.ramms.eater.parser.entity.Section;
import com.ramms.eater.view.ItemSection;
import com.ramms.eater.view.ListSections;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.widget.ListView;

public class HomeActivity extends Activity {
	
	private SectionParser sectionParser;
	private OnClickListenerManager onClickManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
		setContentView(R.layout.main);
		
		sectionParser = new SectionParser();
		onClickManager = new OnClickListenerManager(HomeActivity.this);
		
	}
	
	@Override
	protected void onStart() {
		
		sectionParser.parser();

//		if(sectionParser.getItems().size() > 0) {
		
			ListView listView = (ListView) findViewById(R.id.lstSections);
	
			ItemSection[] items = new ItemSection[sectionParser.getItems().size()]; 
			int i = 0;
			for(Section section : sectionParser.getItems()) {
				items[i++] = new ItemSection(section, onClickManager.getListenerByEntityType(section.getType()));
			}
			
	        listView.setAdapter(new ListSections(items));
        
//		} else {
//			ListView listView = (ListView) findViewById(R.id.lstCasos);
//			
//	        listView.setAdapter(new ListaCaso(new ItemCaso[]{}));
//			Toast.makeText(MisCasosActivity.this, Constants.MSG_VAL01_V17, Toast.LENGTH_SHORT).show();
//		}
		
		super.onStart();
	}
	
}
